<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .form-container {
            text-align: center;
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        input[type="text"] {
            padding: 10px;
            margin: 10px 0;
            width: 200px;
            border-radius: 5px;
            border: 1px solid #ccc;
        }

        input[type="submit"] {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h2>Demo表单</h2>
        <form>
			<input type="text" id="nameInput" placeholder="请输入班级">
            <br>
            <input type="text" id="emailInput" placeholder="请输入关键字">
            <br>
            <input type="submit" value="提交">
        </form>
    </div>
    
        <script>
        document.getElementById("myForm").addEventListener("submit", function(event) {
            event.preventDefault(); // 阻止表单默认提交行为

            var name = document.getElementById("nameInput").value;
            var email = document.getElementById("emailInput").value;

            var xhr = new XMLHttpRequest();
            var url = "http://localhost:6053";  // 服务器地址和端口

            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/json");

            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        console.log("请求成功");
                    } else {
                        console.error("发生错误");
                    }
                }
            };

            var data = JSON.stringify({ name: name, email: email });
            xhr.send(data);

            document.getElementById("nameInput").value = "";
            document.getElementById("emailInput").value = "";
        });
    </script>
</body>
</html>

